package gui.initiatives;


import gui.DateTimePanel;
import gui.EarthPanel;

import javax.swing.Timer;

import simulation.initiatives.EnginePull;

import common.Constants;
import common.SimulationSettings;

public class ClockControlPull extends AbstractClockControl {
  private static final long serialVersionUID = -5822023900023271362L;

  private DateTimePanel pnlDateTime;
  private EarthPanel pnlEarth;
  private ClockPullListener clockUpdater;
  private Timer dateTimeClock;
    
  public ClockControlPull(EarthPanel pnlEarth, SimulationSettings settings) {
    super(settings);    
    clockUpdater = new ClockPullListener(pnlDateTime, pnlEarth, new EnginePull());
    dateTimeClock = new Timer(Constants.DEFAULT_DISPLAY_RATE, clockUpdater);    
  }
  
  public void adjustDisplayRate(int newRate) {
    dateTimeClock.setDelay(newRate);
  }
    
  public void startClock() {
    clockUpdater.setSimTimeStep(settings.getSimTimeStep());
  }
  
  public void pauseClock() {
    dateTimeClock.stop();    
  }
  
  public void resetClock() {
    dateTimeClock.stop();
    pnlDateTime.reset();
    pnlEarth.reset();    
  }
  
}
